<template>
  <div class="collection-list">
    <div class="title">我的收藏</div>
    <div class="uls" v-for="item in collectList" :key="item.id">
      <van-swipe-cell @close="closeSwipe(item)">
        <div class="uls-left">
          <img :src="item.imgSrc" alt="">
        </div>
        <div class="uls-right">
          <div class="collect-top">
            <div class="collect-title">{{item.name}}</div>
            <div class="collect-license">{{item.licenseNum}}</div>
          </div>
          <div class="collect-price">￥{{item.dailyPrice}}</div>
          <div class="collect-company">{{item.company}}</div>
        </div>
        <div class="uls-bottom">
          <button @click="getCollectBtn(item)">取消收藏</button>
        </div>
        <template #right>
          <van-button square text="删除" type="danger" class="delete-button" style="height: 100%" />
        </template>
      </van-swipe-cell>
    </div>
  </div>
</template>
<script>
import { getDeleteCollection, getUpdateList } from '../../api'
import WalletTitle from '../common/WalletTitle.vue'
export default {
  components: { WalletTitle },
  name: 'collectionList',
  data() {
    return {
      collectList: [], // 单个的车辆信息
      collectList2: [] // 将单个的车辆信息加入到数组中
    }
  },
  mounted() {
    this.getCollectList();
  },
  methods: {
    // 右划删除方法
    closeSwipe(e) {
      this.$dialog.confirm({ // 弹框确认是否进入订单页面
        message: '是否要删除收藏？'
      }).then(() => {
        getDeleteCollection(this.$cookie.get('userId'),e.id).then(({data}) => {
          this.getCollectList();
        })
      }).catch(() => {
        return false;
      })
    },
    // 取消收藏方法
    getCollectBtn(e) {
      this.$dialog.confirm({ // 弹框确认是否进入订单页面
        message: '是否要取消收藏？'
      })
        .then(() => {
          getDeleteCollection(this.$cookie.get('userId'), e.id).then(res => {
            this.getCollectList();
          })
        })
        .catch(() => {
          // on cancel
          return false;
        });
    },
    // 渲染收藏列表
    getCollectList() {
      getUpdateList(this.$cookie.get('userId')).then(res => {
        this.collectList = res.data.data;
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.collection-list {
  width: 100%;
  height: 100%;
  padding-bottom: 74px;
  .title {
    width: 100%;
    height: $height;
    line-height: $height;
    text-align: center;
    background-color: #fff;
  }
  .uls /deep/ {
    width: 94%;
    height: 100%;
    margin: 0 auto;
    background-color: #fff;
    margin-top: 10px;
    padding: 6px;
    box-sizing: border-box;
    .van-swipe-cell {
      .van-swipe-cell__wrapper {
        display: flex;
        flex-flow: row wrap;
        .uls-left {
          width: 30%;
          img {
            width: 100%;
            padding: 10px;
            border: 1px solid rgb(210, 210, 210);
          }
        }
        .uls-right {
          width: 70%;
          padding-left: 20px;
          box-sizing: border-box;
          .collect-top {
            width: 100%;
            display: flex;
            flex-flow: row wrap;
            .collect-title {
              margin-right: 10px;
            }
          }
        }
        .uls-bottom {
          width: 100%;
          display: flex;
          justify-content: flex-end;
          button {
            padding: 4px 6px;
            background-color: rgb(235, 235, 235);
            border: 1px solid rgb(210, 210, 210);
            margin-right: 10px;
          }
        }
      }
    }
  }
}
</style>